﻿
Namespace LightSwitchApplication

    Public Class PayHistoryItem



        Private Sub NetPay_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = TaxableGross - If(WTax Is Nothing, 0, WTax) - SumAdditionalDeductionsAfterTax + SumAdditionalNonTaxableIncome
        End Sub

        Private Sub GrossPay_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = RegWage + RegOTTotal + SunOTTotal + HolOTTotal + SumAdditionalTaxableIncome + If(Incentives Is Nothing, 0, Incentives) + If(Allowance Is Nothing, 0, Allowance)
        End Sub

        Private Sub RegWage_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = Rate * If(NoOfDaysWorked Is Nothing, 0, NoOfDaysWorked)
        End Sub

        Private Sub RegOTTotal_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = Rate * If(RegOT Is Nothing, 0, RegOT)
        End Sub

        Private Sub SunOTTotal_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = Rate * If(SunOT Is Nothing, 0, SunOT)
        End Sub

        Private Sub HolOTTotal_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = Rate * If(HolidayOT Is Nothing, 0, HolidayOT)
        End Sub

        'Private Sub TotalAdditionalIncome_Compute(ByRef result As Decimal)
        '    ' Set result to the desired field value
        '    result = If(PayHistoryMoreIncomeItem.Count = 0, 0, PayHistoryMoreIncomeItem.Sum(Function(x) x.Amount))
        'End Sub


        'Private Sub TotalDeduction_Compute(ByRef result As Decimal)
        '    ' Set result to the desired field value
        '    result = If(SSS_MCR Is Nothing, 0, SSS_MCR) + If(WTax Is Nothing, 0, WTax) + TotalDeductionsBeforeTax + (If(Lates Is Nothing, 0, Lates) * (Rate / 8))
        'End Sub

        Private Sub SumAdditionalDeductionsBeforeTax_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            Try
                result = If(PayHistoryMoreDeductions.Count = 0, 0, PayHistoryMoreDeductions.Where(Function(y) y.RefAdditionalDeductionItem.PreTax = True).Sum(Function(x) x.Amount))
            Catch ex As Exception

            End Try




        End Sub

        Private Sub SumAdditionalDeductionsAfterTax_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            Try
                result = If(PayHistoryMoreDeductions.Count = 0, 0, PayHistoryMoreDeductions.Where(Function(y) y.RefAdditionalDeductionItem.PreTax = False).Sum(Function(x) x.Amount))
            Catch ex As Exception

            End Try
        End Sub

        Private Sub TaxableGross_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = GrossPay - TotalDeductionsBeforeTax
        End Sub


        Private Sub SumAdditionalTaxableIncome_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = If(PayHistoryMoreIncomeItem.Count = 0, 0, PayHistoryMoreIncomeItem.Where(Function(y) y.Taxable = True).Sum(Function(x) x.Amount))
        End Sub

        Private Sub TotalDeductionsBeforeTax_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = SumAdditionalDeductionsBeforeTax + If(SSS_MCR Is Nothing, 0, SSS_MCR) + (If(Lates Is Nothing, 0, Lates) * (Rate / 8))
        End Sub

        Private Sub SumAdditionalNonTaxableIncome_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            result = If(PayHistoryMoreIncomeItem.Count = 0, 0, PayHistoryMoreIncomeItem.Where(Function(y) y.Taxable = False).Sum(Function(x) x.Amount))
        End Sub

        Private Sub Leaves_Compute(ByRef result As Decimal)
            ' Set result to the desired field value
            Dim filedLeaves = From fLeaves In Me.DataWorkspace.ApplicationData.LeaveHistories
                              Where fLeaves.EmployeeItem.EmployeeID = EmployeeItem.EmployeeID AndAlso
                              ((CDate(fLeaves.EndDate) >= CDate(PayPeriodItem.StartDate) AndAlso CDate(fLeaves.EndDate) <= CDate(PayPeriodItem.EndDate)) OrElse
                               (CDate(fLeaves.StartDate) >= CDate(PayPeriodItem.StartDate) AndAlso CDate(fLeaves.StartDate) <= CDate(PayPeriodItem.EndDate)))

            For Each item In filedLeaves
                Dim x As Integer = 1
            Next
        End Sub
    End Class

End Namespace
